<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" href="/assets/css/base.css">
  <link rel="stylesheet" href="/assets/css/iconfont.css">
  <link rel="stylesheet" href="/assets/css/public.css">
  <link rel="stylesheet" href="/assets/css/detail.css">
</head>

<body>
  <div class="container">
    @@include('./assets/common/home/nav.html')

    <div class="content">
      <div class="item">
        <div class="item-box">
          <div class="box">

          </div>

          <div class="comment">
            <form>
              <textarea></textarea>
              <input type="submit" value="提交评论">
            </form>
          </div>
          <div class="item recommend">
            @@include('./assets/common/home/hotRecommend.html')
          </div>
        </div>


      </div>


      <div class="footer">
        <p>© 2016 XIU主题演示 本站主题由 themebetter 提供</p>
      </div>

      @@include('./assets/common/home/rightData.html')
    </div>
</body>

@@include('./assets/common/base.html')
<script src="./js/home/home-hot.js"></script>

<script type="text/template" id="comment">
  <div class="breadcrumb">
    <dl>
      <dt>当前位置：</dt>
      <dd>
        <a href="javascript:;">{{commentList.category.title}} > </a>
      </dd>
      <dd>
        {{commentList.title}}
      </dd>
    </dl>
  </div>
  <h2 class="title">
    <a href="javascript:;">{{commentList.title}}</a>
  </h2>
  <div class="meta">
    <span>{{commentList.author.nickName}} 发布于 {{handleDate(commentList.author.createTime)}}</span>
    <span>分类: <a href="javascript:;">{{commentList.category.title}}</a></span>
    <span>阅读: ({{commentList.meta.views}})</span>
    <span>评论: ({{commentList.meta.comments}})</span>
  </div>
  {{commentList.content}}
</div>

</script>

<!-- 根据id值获取数据 -->
<script>
  $(function () {

    function formDate(dateStr) {
      let date = new Date(dateStr);
      return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()
    }
    // 处理url地址 获取id值
    const idUrl = window.location.search
    const idStr = idUrl.split('?')[1]
    const id = idStr.split('=')[1]

    $.ajax({
      url: baseUrl + '/posts/' + id,
      type: 'get',
      success(res) {
        const newHtml = template('comment', {
          commentList: res,
          handleDate: formDate
        })
        $('.content .item .item-box .box').html(newHtml)
      },
      error(err) {
        console.log(err);
      }
    })
  })
</script>

</html>